#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int T;
int n,m,L,V;
int d[N],v[N],a[N],p[N];
int y;
int j,f;
int mixn = 1e6 + 10,maxn = 0;
bool b[N];
int main () {
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin >> T;
    while(T --){
        int ans = 0,que = 0;
        cin >> n >> m >> L >> V;
        for(int i = 1;i <= n;i ++){
            memset(b,0,sizeof(b));
            cin >> d[i] >> v[i] >> a[i];
            if(a[i] == 0){
                y ++;
            }
            if(a[i] > 0){
                j ++;
            }
            if(a[i] < 0){
                f ++;
            }
        }
        if(y == n){
            for(int i = 1;i <= n;i ++){
                if(v[i] > V) ans ++;
            }
            cout << ans << " " <<  m - 1 << endl;
            continue;
        }
        for(int i = 1;i <= m;i ++){
            cin >> p[i];
            maxn = max(maxn,p[i]);
            mixn = min(mixn,p[i]);
        }
   for(int i = 1;i <= n;i ++){
        if(a[i] == 0){
            if(v[i] > V) ans ++;
            continue;
        }
        int v1 = V;
        double s = (v1 * v1 - v[i] * v[i]) / double(a[i] * 2);
        double zong = v[i] + s;
        if(a[i] > 0){
            if(zong <= maxn){
                ans ++;
              int wei = lower_bound(p + 1,p + m + 1,zong) - p;
                b[wei] = 1;
                }
            }
            if(a[i] < 0){
                if(zong >= mixn){
                    int wei = lower_bound(p + 1,p + m + 1,zong) - p;
                    if(zong >= p[wei] && zong <= p[wei + 1]){
                      ans ++;
                      b[wei - 1] = 1;
                    }
                }
            }
        }
        for(int i = 1;i <= n;i ++){
            if(b[i] == 0) {
                    que ++;
            }
        }
        cout << ans << " " << que << endl;
    }
    return 0;
}

